package com.algorithm.arrays;
/*
 *@Author:DOWN
 *@Date:2021/12/27 18:23
 *@Comment:
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

public class Solution {

    private static final String Push = "Push";
    private static final String Pop = "Pop";

    public List<String> buildArray(int[] target, int n) {
        List<String> arrgs = new ArrayList<>();
        Stack<Integer> stack = new Stack<>();
        for (int add = 1, i = 0; i < target.length && add <= n; add++) {
            arrgs.add(Push);
            stack.add(add);
            if (stack.peek() == target[i]) {
                i++;
            } else {
                stack.pop();
                arrgs.add(Pop);
            }
        }
        return arrgs;
    }
}
